package com.base.controller;

import com.base.comm.CommContent;
import com.base.po.tbk.TbkChoiceGoods;
import com.base.service.LogsService;
import com.base.service.TbkChoiceGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * 修改精选单品信息服务端
 * 
 * @author f
 *
 */
@Controller
@RequestMapping("/admin")
public class update_ChoiceGoods {

	@Autowired
	private LogsService logsService; // log日志
	@Autowired
	private TbkChoiceGoodsService tbkChoiceGoodsService; // 商品分类信息

	@RequestMapping("/updateChoiceGoods")
	public ModelAndView updateChoiceGoods(HttpServletRequest request, String id, Integer type) throws Exception {
		ModelAndView modelAndView = new ModelAndView();

		TbkChoiceGoods tbkChoiceGoods = tbkChoiceGoodsService.selectByPrimaryKey(id);

		request.setAttribute("tbkChoiceGoods", tbkChoiceGoods);
		request.setAttribute("type", type);
        modelAndView.setViewName("jsp/update_ChoiceGoods");
		return modelAndView;
	}

	@RequestMapping(value = "/toUpdateChoiceGoods", method = RequestMethod.POST)
	public @ResponseBody int toUpdateChoiceGoods(HttpServletRequest request, TbkChoiceGoods tbkChoiceGoods) throws Exception {
		if (request.getSession().getAttribute("adminUserId") == null) return -1; // 未登录
		return tbkChoiceGoodsService.updateByPrimaryKeySelective(tbkChoiceGoods); // 修改
	}
}
